/**
 * URLContent.java 25 avr. 2006
 * 
 * Copyright (c) 2006 Emmanuel PUYBARET / eTeks <info@eteks.com>. All Rights
 * Reserved.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.windu2b.jcaddie.tools;

import java.io.*;
import java.net.*;

import org.windu2b.jcaddie.model.*;

/**
 * URL content for files, images...
 * 
 * @author Emmanuel Puybaret, windu.2b
 * 
 */
public class URLContent implements Content
{
	/**
	 * 
	 */
	private static final long	serialVersionUID	= -7866488183277459140L;


	private URL	              url;




	/**
	 * Constructeur par recopie
	 * 
	 * @param url
	 */
	public URLContent( URL url )
	{
		try
		{
			this.url = new URL( url.toString() );
		}
		catch ( MalformedURLException ex )
		{
			ex.printStackTrace();
		}
	}




	public URLContent( Content content )
	{
		try
		{
			this.url = new URL( content.toString() );
		}
		catch ( MalformedURLException ex )
		{
			ex.printStackTrace();
		}
	}




	/**
	 * Returns the URL of this content.
	 */
	public URL getUrl()
	{
		return url;
	}




	/**
	 * Returns an InputStream on the URL content.
	 * 
	 * @throws IOException
	 *             if URL stream can't be opened.
	 */
	public InputStream openStream() throws IOException
	{
		return url.openStream();
	}




	@Override
	public String toString()
	{
		return url.toString();
	}
}